﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace LightingServer
{
    public class ColIndexSetter
    {
        public void SetIndex(TableRef tableRef, IList<string> headers)
        {
            foreach (ColRef colRef in tableRef.RefList)
            {
                colRef.Index = headers.IndexOf(colRef.ColName);
            }
        }
    }

    public class BuilderCreator
    {
        public object Create(TableRef tableRef, IList<string> data)
        {
            try
            {
                object instance = Activator.CreateInstance(tableRef.ClassType);
                foreach (ColRef colRef in tableRef.RefList)
                {
                    string value = data[colRef.Index];
                    MethodInfo methodInfo = tableRef.ClassType.GetMethod(colRef.CallMethod);
                    methodInfo.Invoke(instance, new object[] { value });
                }
                return instance;
            }
            catch
            {
            }
            return null;
        }
    }
}
